<template>
  <div>
   <!-- Io信息 -->

  </div>
</template>
<script setup lang="ts">
import {ref} from 'vue'
import { ElMessage } from 'element-plus'

var socket = new WebSocket('http://localhost:9069/connection')
console.log(socket,'oopp')

/* 0时为第一次连接后台 */
var ind=ref<number>(0)
var title=ref<string>('already connect now')


/* 发送消息 */
const open=()=>{
  if(ind.value==0){
  socket.send(title.value)
  }
}

/* 接受消息 */
const message=(e)=>{
  if(JSON.parse(e.data)['data']['msg']=='ok'){
    ElMessage.success('io is connect ok')
  }
}


/* 初始化 */
const init=()=>{
  socket.onopen=()=>open()
  socket.onmessage=message
}
init()


</script>
<style scoped lang="scss"></style>